public class Test {
    /*
    和为 K 的子数组
    class Solution {
    public int subarraySum(int[] nums, int k) {
        HashMap<Integer,Integer> hash = new HashMap<>();
        int ret = 0 , sum = 0;
        hash.put(0,1);
        for(int x : nums) {
            sum += x;
            if(hash.containsKey(sum-k)) {
                ret += hash.get(sum-k);
            }
            hash.put(sum,hash.getOrDefault(sum,0) + 1);
        }
        return ret;
    }
}
    消失的两个数字
    class Solution {
    public int[] missingTwo(int[] nums) {
        int ret = 0, ret0 = 0, ret1 = 0;

        // 还原缺少的俩个整数的^
        for (int x : nums) {
            ret ^= x;
        }
        for (int i = 1; i <= nums.length + 2; i++) {
            ret ^= i;
        }
        // 进行分组 使用lowbit 去除最右边的1
        ret &= (-ret);

        // 还原数组 进行分组
        for (int x : nums) {
            if ((ret & x) == 0) {
                ret0 ^= x;
            } else {
                ret1 ^= x;
            }
        }
        for (int i = 1; i <= nums.length + 2; i++) {
            if ((ret & i) == 0) {
                ret0 ^= i;
            } else {
                ret1 ^= i;
            }
        }

        return new int[] { ret0, ret1 };
    }
}
    长度最小的连续子数组
    public int minSubarray (int[] nums, int target) {
        // write code here
        int ret = nums.length;
        int sum = 0;
        for(int right = 0 ,left = 0 ; right < nums.length ;right++) {
           //进窗口
           sum += nums[right];
           while(sum >= target) {
            ret = Math.min(ret,right - left + 1 );
            int out = nums[left];
            sum-=out;
            left++;
           }

        }
        return ret;
    }
    和可被 K 整除的子数组
    .class Solution {
    public int subarraysDivByK(int[] nums, int k) {
        //放的余数
        HashMap<Integer,Integer> hash = new HashMap<>();
        hash.put(0,1);
        int count = 0 ,sum = 0;
        for(int x : nums) {
            sum+=x;
            //同余定理
            int mod = (sum %k + k) %k;
            if(hash.containsKey(mod)) {
                count += hash.get(mod);
            }
            hash.put(mod,hash.getOrDefault(mod,0)+1);
        }
        return count;
    }
}
     */
}
